# DEPENDEBCIES
lappend auto_path d:/codes/tcl/tank/lib
package require TclOO
package require anonymous

# PACKAGE
package provide lazySeq 0.1

# IMPORT

# ARGS

# MAIN
oo::class create lazySeq {
    variable buffer generater

    constructor {g {initVal {}}} {
        # generater is an anonymous
        foreach {vars body} $g {}
        set body "namespace upvar [self namespace] buffer [lindex $vars 0]\n$body"
        set generater [list [lreplace $vars 0 0] $body]
        set buffer $initVal

        my eval namespace import ::anonymous::*
    }

    method next {} {
        set r [~ $generater]
        lappend buffer $r
        return $r
    }

    method range {from to} {
        set len [llength $buffer]
        while {$len <= $to} {
            my next
            incr len
        }
        return [lrange $buffer $from $to]
    }
}


